package com.swxy.club.controller;

import com.swxy.club.dto.bo.*;
import com.swxy.club.result.Result;
import com.swxy.club.service.activity.ActivityMemberService;
import com.swxy.club.service.activity.ActivityService;
import com.swxy.club.service.code.CheckinCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author 易
 */

@RestController
@RequestMapping("/api")
@RequiredArgsConstructor
@Api(tags = "活动模块")
public class ActivityController {

    private final ActivityService activityService;
    private final CheckinCodeService checkinCodeService;
    private final ActivityMemberService activityMemberService;

    @GetMapping("/{id}")
    @ApiOperation("根据id查找活动")
    public Result getActivityById(@PathVariable Integer id) {
        return Result.success(activityService.getActivityById(id));
    }

    @PostMapping("pageSelect")
    @ApiOperation("分页查询活动")
    public Result pageSelect(@RequestBody PageBo form) {
        return Result.success(activityService.pageSelect(form));
    }

    @PostMapping("/addActivity")
    @ApiOperation("创建活动")
    public Result addActivity(@RequestBody ActivityAddBo form) {
        activityService.addActivity(form);
        return Result.success("创建成功");
    }

    @PostMapping("/approveActivity")
    @ApiOperation("活动审批")
    public Result approveActivity(@RequestBody ApproveActivityBo form) {
        activityService.approveActivity(form);
        return Result.success("审批成功");
    }

    @PostMapping("/code")
    @ApiOperation("获取签到码")
    public Result generateCheckinCode(@RequestBody CodeAddBo codeAddBo) {
        return Result.success(checkinCodeService.generateCheckinCode(codeAddBo));
    }

    @PostMapping("/checkin")
    @ApiOperation("签到")
    public Result checkin(@RequestBody CheckinBo checkinBo) {
        checkinCodeService.checkin(checkinBo);
        return Result.success("签到成功");
    }

    @GetMapping("/join/{id}")
    @ApiOperation("加入活动")
    public Result joinActivity(@PathVariable Integer id) {
        activityMemberService.joinActivity(id);
        return Result.success("参加成功");
    }

    @GetMapping("getCurrentUserActivity")
    @ApiOperation("获取当前用户参加的活动")
    public Result getCurrentUserActivity() {
        return Result.success(activityMemberService.getCurrentUserActivity());
    }

}
